home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / AI.TRM < prev    next >
Text File  |  1992-03-25  |  8KB  |  349 lines

  1. /*
  2.  * $Id: ai.trm,v 3.26 92/03/24 22:35:00 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - ai.trm */
  6. /*
  7.  * Copyright (C) 1991, 1992   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *     aifm
  25.  *
  26.  * AUTHORS
  27.  *  Ray Ghanbari
  28.  * 
  29.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  30.  *
  31.  * The 'aifm' driver produces files editable by Adobe Illustrator 3.0
  32.  * To change font to Courier and font size to 20pts use 
  33.  * 'set term aifm "Courier" 20'.
  34.  * To switch to color output use
  35.  * 'set term aifm color'.
  36.  */
  37.  
  38.  
  39. /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu, 
  40.  *    based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  41.  
  42. char ai_font[MAX_ID_LEN+1] = "Times-Roman" ; /* name of font */
  43. int ai_fontsize = 14;                     /* size of font in pts */
  44. BOOLEAN ai_color = FALSE;
  45. BOOLEAN ai_stroke = FALSE;
  46. int ai_page=0;            /* page count */
  47. int ai_path_count=0;     /* count of lines in path */
  48. int ai_ang=0;            /* text angle */
  49. enum JUSTIFY ai_justify=LEFT;    /* text is flush left */
  50.  
  51.  
  52. #define AI_XOFF    50    /* page offset in pts */
  53. #define AI_YOFF    50
  54.  
  55. #define AI_XMAX 5000
  56. #define AI_YMAX 3500
  57.  
  58. #define AI_XLAST (AI_XMAX - 1)
  59. #define AI_YLAST (AI_YMAX - 1)
  60.  
  61. #define AI_VTIC (AI_YMAX/80)
  62. #define AI_HTIC (AI_YMAX/80)
  63.  
  64. #define AI_SC (10.0)                /* scale is 1pt = 10 units */
  65. #define AI_LW (0.5*AI_SC)        /* linewidth = 0.5 pts */
  66.  
  67. #define AI_VCHAR (14*AI_SC)        /* default is 14 point characters */
  68. #define AI_HCHAR (14*AI_SC*6/10)
  69.  
  70.  
  71. AI_options()
  72. {
  73.     extern struct value *const_express();
  74.     extern double real();
  75.  
  76.     if (!END_OF_COMMAND) {
  77.         if (almost_equals(c_token,"d$efault")) {
  78.             ai_color=FALSE;
  79.             strcpy(ai_font,"Times-Roman");
  80.             ai_fontsize = 14;
  81.             c_token++;
  82.         }
  83.     }
  84.  
  85.     if (!END_OF_COMMAND) {
  86.         if (almost_equals(c_token,"m$onochrome")) {
  87.             ai_color=FALSE;
  88.             c_token++;
  89.         }
  90.         else if (almost_equals(c_token,"c$olor")) {
  91.             ai_color=TRUE;
  92.             c_token++;
  93.         }
  94.     }
  95.  
  96.     if (!END_OF_COMMAND && isstring(c_token)) {
  97.         quote_str(ai_font,c_token);
  98.         c_token++;
  99.     }
  100.  
  101.     if (!END_OF_COMMAND) {
  102.         /* We have font size specified */
  103.         struct value a;
  104.         ai_fontsize = (int)real(const_express(&a));
  105.         c_token++;
  106.         term_tbl[term].v_char = (unsigned int)(ai_fontsize*AI_SC);
  107.         term_tbl[term].h_char = (unsigned int)(ai_fontsize*AI_SC*6/10);
  108.     }
  109.  
  110.     sprintf(term_options,"%s \"%s\" %d",
  111.         ai_color ? "color" : "monochrome",ai_font,ai_fontsize);
  112. }
  113.  
  114.  
  115. AI_init()
  116. {
  117. struct termentry *t = &term_tbl[term];
  118. int i;
  119.     ai_page = 0;
  120.     fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  121.     fprintf(outfile,"%%%%BoundingBox: %d %d %d %d\n", AI_XOFF,AI_YOFF,
  122.         (int)((AI_XMAX)/AI_SC+0.5+AI_XOFF), 
  123.         (int)((AI_YMAX)/AI_SC+0.5+AI_YOFF) );
  124.     fprintf(outfile,"%%%%Template:\n");
  125.     fprintf(outfile,"%%%%EndComments\n");
  126.     fprintf(outfile,"%%%%EndProlog\n");
  127. }
  128.  
  129.  
  130. AI_graphics()
  131. {
  132. struct termentry *t = &term_tbl[term];
  133.     ai_page++;
  134. /*    fprintf(outfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
  135.     fprintf(outfile,"0 G\n");
  136.     fprintf(outfile,"1 j\n");
  137.     fprintf(outfile,"1 J\n");
  138.     fprintf(outfile,"u\n");
  139.     ai_path_count = 0;
  140.     ai_stroke = FALSE;
  141. }
  142.  
  143.  
  144. AI_text()
  145. {
  146.     if (ai_stroke) {
  147.         fprintf(outfile,"S\n");
  148.         ai_stroke = FALSE;
  149.     }
  150.     fprintf(outfile,"U\n");
  151.     ai_path_count = 0;
  152. }
  153.  
  154.  
  155. AI_reset()
  156. {
  157.     fprintf(outfile,"%%%%Trailer\n");
  158. /*    fprintf(outfile,"%%%%Pages: %d\n",ai_page);*/
  159. }
  160.  
  161.  
  162. AI_linetype(linetype)
  163. int linetype;
  164. {
  165.     if (ai_stroke) {
  166.         fprintf(outfile,"S\n");
  167.         ai_stroke = FALSE;
  168.     }
  169.     switch(linetype) {
  170.         case -2 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC*2.0);
  171.                 if (ai_color) {
  172.                     fprintf(outfile,"0 0 0 1 K\n");
  173.                 }
  174.                 else {                
  175.                     fprintf(outfile,"[] 0 d\n");
  176.                 }
  177.                 break;
  178.                 
  179.         case -1 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC/2.0);
  180.                 if (ai_color) {
  181.                     fprintf(outfile,"0 0 0 1 K\n");
  182.                 }
  183.                 else {                
  184.                     fprintf(outfile,"[1 2] 0 d\n");
  185.                 }
  186.                 break;
  187.                 
  188.         case 0 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  189.                 if (ai_color) {
  190.                     fprintf(outfile,"1 0 1 0 K\n");
  191.                 }
  192.                 else {                
  193.                     fprintf(outfile,"[] 0 d\n");
  194.                 }
  195.                 break;
  196.                 
  197.         case 1 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  198.                 if (ai_color) {
  199.                     fprintf(outfile,"1 1 0 0 K\n");
  200.                 }
  201.                 else {                
  202.                     fprintf(outfile,"[4 2] 0 d\n");
  203.                 }
  204.                 break;
  205.                 
  206.         case 2 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  207.                 if (ai_color) {
  208.                     fprintf(outfile,"0 1 1 0 K\n");
  209.                 }
  210.                 else {                
  211.                     fprintf(outfile,"[2 3] 0 d\n");
  212.                 }
  213.                 break;
  214.                 
  215.         case 3 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  216.                 if (ai_color) {
  217.                     fprintf(outfile,"0 1 0 0 K\n");
  218.                 }
  219.                 else {                
  220.                     fprintf(outfile,"[1 1.5] 0 d\n");
  221.                 }
  222.                 break;
  223.                 
  224.         case 4 :  fprintf(outfile,"%f w\n",AI_LW/AI_SC);
  225.                 if (ai_color) {
  226.                     fprintf(outfile,"1 0 0 0 K\n");
  227.                 }
  228.                 else {                
  229.                     fprintf(outfile,"[5 2 1 2] 0 d\n");
  230.                 }
  231.                 break;
  232.                 
  233.         case 5 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  234.                 if (ai_color) {
  235.                     fprintf(outfile,"0 0 1 0 K\n");
  236.                 }
  237.                 else {                
  238.                     fprintf(outfile,"[4 3 1 3] 0 d\n");
  239.                 }
  240.                 break;
  241.                 
  242.         case 6 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  243.                 if (ai_color) {
  244.                     fprintf(outfile,"0 0 0 1 K\n");
  245.                 }
  246.                 else {                
  247.                     fprintf(outfile,"[2 2 2 4] 0 d\n");
  248.                 }
  249.                 break;
  250.                 
  251.         case 7 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  252.                 if (ai_color) {
  253.                     fprintf(outfile,"0 0.7 1 0 K\n");
  254.                 }
  255.                 else {                
  256.                     fprintf(outfile,"[2 2 2 2 2 4] 0 d\n");
  257.                 }
  258.                 break;
  259.                 
  260.         case 8 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  261.                 if (ai_color) {
  262.                     fprintf(outfile,"0.5 0.5 0.5 0 K\n");
  263.                 }
  264.                 else {                
  265.                     fprintf(outfile,"[2 2 2 2 2 2 2 4] 0 d\n");
  266.                 }
  267.                 break;
  268.         }
  269.                 
  270.     ai_path_count = 0;
  271. }
  272.  
  273.  
  274. AI_move(x,y)
  275. unsigned int x,y;
  276. {
  277.     if (ai_stroke) fprintf(outfile,"S\n");
  278.     fprintf(outfile,"%.2f %.2f m\n", x/AI_SC, y/AI_SC);
  279.     ai_path_count += 1;
  280.     ai_stroke = TRUE;
  281. }
  282.  
  283.  
  284. AI_vector(x,y)
  285. unsigned int x,y;
  286. {
  287.     fprintf(outfile,"%.2f %.2f l\n", x/AI_SC, y/AI_SC);
  288.     ai_path_count += 1;
  289.     ai_stroke = TRUE;
  290.     if (ai_path_count >= 400) {
  291.         fprintf(outfile,"S\n%.2f %.2f m\n",x/AI_SC,y/AI_SC);
  292.         ai_path_count = 0;
  293.     }
  294. }
  295.  
  296.  
  297. AI_put_text(x,y,str)
  298. unsigned int x, y;
  299. char *str;
  300. {
  301. char ch;
  302.     if (ai_stroke) {
  303.         fprintf(outfile,"S\n");
  304.         ai_stroke = FALSE;
  305.     }
  306.     switch(ai_justify) {
  307.         case LEFT :   fprintf(outfile,"/_%s %d 0 0 0 z\n",ai_font,ai_fontsize);
  308.             break;
  309.         case CENTRE : fprintf(outfile,"/_%s %d 0 0 1 z\n",ai_font,ai_fontsize);
  310.             break;
  311.         case RIGHT :  fprintf(outfile,"/_%s %d 0 0 2 z\n",ai_font,ai_fontsize);
  312.             break;
  313.     }
  314.     if (ai_ang==0) {
  315.         fprintf(outfile,"[ 1 0 0 1 %.2f %.2f] e\n",
  316.             x/AI_SC,y/AI_SC - ai_fontsize/3.0);
  317.     }
  318.     else {
  319.         fprintf(outfile,"[ 0 1 -1 0 %.2f %.2f] e\n",
  320.             x/AI_SC - ai_fontsize/3.0,y/AI_SC);
  321.     }
  322.         
  323.     putc('(',outfile);
  324.     ch = *str++;
  325.     while(ch!='\0') {
  326.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  327.             putc('\\',outfile);
  328.         putc(ch,outfile);
  329.         ch = *str++;
  330.     }
  331.     fprintf(outfile,") t\nT\n");
  332.     ai_path_count = 0;
  333. }
  334.  
  335. int AI_text_angle(ang)
  336. int ang;
  337. {
  338.     ai_ang=ang;
  339.     return TRUE;
  340. }
  341.  
  342. int AI_justify_text(mode)
  343. enum JUSTIFY mode;
  344. {
  345.     ai_justify=mode;
  346.     return TRUE;
  347. }
  348.  
  349.